﻿Imports System.Data.SqlClient

Public Class TaiKhoanBUS

    Public Shared Function GetAll() As DataTable
        Dim listTaiKhoan As New DataTable()

        listTaiKhoan = TaiKhoanDAO.GetAll()

        Return listTaiKhoan
    End Function

    Public Shared Function GetByID(ByVal UID As String) As List(Of TaiKhoanDTO)
        Dim listTaiKhoan As List(Of TaiKhoanDTO)

        Dim paraUID As SqlParameter = New SqlParameter("Username", SqlDbType.VarChar)
        paraUID.Direction = ParameterDirection.Input
        paraUID.Value = UID

        listTaiKhoan = TaiKhoanDAO.GetByID(paraUID)

        Return listTaiKhoan
    End Function

    Public Shared Sub Insert(ByVal taikhoan As TaiKhoanDTO)
        Dim parameters(2) As SqlParameter

        Dim para As SqlParameter = New SqlParameter("Username", SqlDbType.VarChar)
        para.Direction = ParameterDirection.Input
        para.Value = taikhoan.strUsername
        parameters(0) = para

        para = New SqlParameter("Password", SqlDbType.NVarChar)
        para.Direction = ParameterDirection.Input
        para.Value = taikhoan.strPassword
        parameters(1) = para

        para = New SqlParameter("MaLoaiTK", SqlDbType.NVarChar)
        para.Direction = ParameterDirection.Input
        para.Value = taikhoan.iMaLoaiTK
        parameters(2) = para

        TaiKhoanDAO.Insert(parameters)
    End Sub

    Public Shared Sub Delete(ByVal paraID As SqlParameter)
        TaiKhoanDAO.Delete(paraID)
    End Sub

    Public Shared Sub Update(ByVal taikhoan As TaiKhoanDTO)
        Dim parameters(2) As SqlParameter

        Dim para As SqlParameter = New SqlParameter("Username", SqlDbType.VarChar)
        para.Direction = ParameterDirection.Input
        para.Value = taikhoan.strUsername
        parameters(0) = para

        para = New SqlParameter("Password", SqlDbType.NVarChar)
        para.Direction = ParameterDirection.Input
        para.Value = taikhoan.strPassword
        parameters(1) = para

        para = New SqlParameter("MaLoaiTK", SqlDbType.NVarChar)
        para.Direction = ParameterDirection.Input
        para.Value = taikhoan.iMaLoaiTK
        parameters(2) = para
        TaiKhoanDAO.Update(parameters)

    End Sub

    Public Shared Sub delete_TaiKhoan(ByVal username As String)
        Dim parameters(1) As SqlParameter

        Dim para As SqlParameter = New SqlParameter("Username", SqlDbType.VarChar)
        para.Direction = ParameterDirection.Input
        para.Value = username
        parameters(0) = para

        TaiKhoanDAO.Delete(para)
    End Sub
    Public Shared Function KiemTraDayDu(ByVal tentaikhoan As String, ByVal matkhau As String)
        Dim kq As Boolean
        If Not tentaikhoan = "" Then
            If Not matkhau = "" Then
                kq = True
            Else
                kq = False
            End If
        Else
            kq = False
        End If
        Return kq
    End Function
    Public Shared Function TimKiemTKTheoLoaiTK(ByVal maloaiTK As Integer) As DataTable
        Dim listTaiKhoan As New DataTable()

        Dim para As SqlParameter = New SqlParameter("maloaiTK", SqlDbType.Int)
        para.Direction = ParameterDirection.Input
        para.Value = maloaiTK

        listTaiKhoan = TaiKhoanDAO.TimKiemTKTheoLoaiTK(para)

        Return listTaiKhoan
    End Function
End Class
